using System;
using System.Collections;
using System.Collections.Generic;
using AdvancedInspector;
using Photon;
using Rilisoft.MiniJson;
using UnityEngine;
using UnityEngine.SceneManagement;

[AdvancedInspector(true)]
public class bonuseManager : Photon.MonoBehaviour
{
	public static bonuseManager thisScript;

	public static float BONUS_VISIBLE_DISTANCE = 140f;

	public GameObject objSpisokAllBonuse;

	public GameObject objPointItemRespaw;

	public GameObject objPointGunRespaw;

	public WeaponManager weaponMan;

	public LayerMask layerForSpawn;

	public List<BoxCollider> arrItemBonuseRespawn;

	private BoxCollider[] arrGunBonuseRespawn;

	public AudioClip soundBonuse;

	public List<BonuseItem> listAllBonuse = new List<BonuseItem>();

	public float distGetBonuse = 1.5f;

	public float distGetBonuseInCar = 2f;

	public float timeAddItemBonuse = 1f;

	public float timeAddGunBonuse = 1f;

	public int maxKolBonuseItem = 15;

	public int maxKolBonuseGun = 15;

	private int countRandomBonuse = 25;

	private int countIterationRandom = 25;

	private BoxCollider pointRespawn;

	private List<BoxCollider> predPointRespawn = new List<BoxCollider>();

	private bool iAmCreateBonuse;

	public BonuseItem[] arrAllTypeBonuse;

	public Material materialRed;

	public Material materialGreen;

	public Material materialOrange;

	public Material materialBlue;

	public void SpawnBonuses()
	{
		InfoFromPoint instance = InfoFromPoint.instance;
		if (instance == null || instance.listPointSpawn == null || instance.listPointSpawn.Count == 0)
		{
			return;
		}
		float num = (float)instance.listPointSpawn.Count / (float)ParametersLevel.instance.MaxCountItemBonuse;
		float num2 = UnityEngine.Random.Range(0f, num - 0.1f);
		for (int i = 0; i < instance.listPointSpawn.Count; i++)
		{
			if (instance.listPointSpawn[i].options)
			{
				instance.goWithCollider.transform.position = instance.listPointSpawn[i].pos;
				InstantBonuse(instance.listPointSpawn[i].listBonuse, instance.listPointSpawn[i].timeForRespawnBonuse, instance.listPointSpawn[i].pos);
				continue;
			}
			num2 += 1f;
			if (num2 >= num)
			{
				num2 -= num;
				instance.goWithCollider.transform.position = instance.listPointSpawn[i].pos + Vector3.down;
				CreateBonuseType(typeGroupBonuse.Item, false, instance.listPointSpawn[i].pos, 0, 0f, false);
			}
		}
		InfoFromPoint.instance.goWithCollider.transform.position = Vector3.down * 1000f;
	}

	private void Awake()
	{
		if (!(SceneManager.GetActiveScene().name == "Tutorial"))
		{
			thisScript = this;
			if (ParametersLevel.instance != null)
			{
				timeAddItemBonuse = ParametersLevel.instance.timeAddItemBonuse;
				maxKolBonuseItem = ParametersLevel.instance.MaxCountItemBonuse;
			}
			if (objPointItemRespaw == null)
			{
				objPointItemRespaw = GameObject.FindGameObjectWithTag("BonuseItemRespawn");
			}
			if (objPointItemRespaw == null)
			{
				objPointItemRespaw = GameObject.FindGameObjectWithTag("BonuseItemRespawn");
			}
			if (objSpisokAllBonuse == null)
			{
				objSpisokAllBonuse = GameObject.FindGameObjectWithTag("Spisok_Bonuse");
			}
			arrAllTypeBonuse = Resources.LoadAll<BonuseItem>("Bonuse/");
		}
	}

	private void Start()
	{
		if (GameController.instance.curTypeGame == TypeGame.race || GameController.instance.curTypeGame == TypeGame.tanks)
		{
			base.enabled = false;
			return;
		}
		int num = 0;
		if (arrAllTypeBonuse != null)
		{
			BonuseItem[] array = arrAllTypeBonuse;
			foreach (BonuseItem bonuseItem in array)
			{
				num = 0;
				BonuseItem[] array2 = arrAllTypeBonuse;
				foreach (BonuseItem bonuseItem2 in array2)
				{
					if (bonuseItem.typeGroup == bonuseItem2.typeGroup)
					{
						num += bonuseItem2.verAddThisBonuse;
					}
				}
				bonuseItem.totalVerGroup = num;
			}
		}
		if (settings.learningCompleted)
		{
			InitVaribels();
			if (settings.offlineMode || PhotonNetwork.isMasterClient)
			{
				SpawnBonuses();
			}
		}
		settings.gameModeChange += GameModeChanged;
	}

	private void OnEnable()
	{
		TDMController.ChangeTeam += ChangeTeam;
	}

	private void OnDisable()
	{
		TDMController.ChangeTeam -= ChangeTeam;
	}

	private void Update()
	{
		AnimateBonus();
	}

	private void AnimateBonus()
	{
		float num = Time.time - (float)Math.Truncate(Time.time);
		float a = 0.5f + ((!(num < 0.5f)) ? (1f - num) : num);
		Color color = materialRed.GetColor("_TintColor");
		color.a = a;
		materialRed.SetColor("_TintColor", color);
		color = materialBlue.GetColor("_TintColor");
		color.a = a;
		materialBlue.SetColor("_TintColor", color);
		color = materialOrange.GetColor("_TintColor");
		color.a = a;
		materialOrange.SetColor("_TintColor", color);
		color = materialGreen.GetColor("_TintColor");
		color.a = a;
		materialGreen.SetColor("_TintColor", color);
		color = materialRed.GetColor("_TintColor");
		color.a = a;
		materialRed.SetColor("_TintColor", color);
		float value = 1.5f + ((!(num < 0.5f)) ? (1f - num) : num);
		materialRed.SetFloat("_Scale", value);
		materialBlue.SetFloat("_Scale", value);
		materialOrange.SetFloat("_Scale", value);
		materialGreen.SetFloat("_Scale", value);
	}

	private void OnDestroy()
	{
		settings.gameModeChange -= GameModeChanged;
	}

	private void InitVaribels()
	{
		if (GameController.instance != null && GameController.instance.playerScript != null)
		{
			weaponMan = GameController.instance.playerScript.GetComponent<WeaponManager>();
		}
		if (objPointItemRespaw != null)
		{
			arrItemBonuseRespawn.AddRange(objPointItemRespaw.GetComponentsInChildren<BoxCollider>());
		}
		if (objPointGunRespaw != null)
		{
			arrGunBonuseRespawn = objPointGunRespaw.GetComponentsInChildren<BoxCollider>();
		}
		if (arrItemBonuseRespawn != null)
		{
			foreach (BoxCollider item in arrItemBonuseRespawn)
			{
				item.enabled = false;
			}
		}
		if (arrGunBonuseRespawn != null)
		{
			BoxCollider[] array = arrGunBonuseRespawn;
			foreach (BoxCollider boxCollider in array)
			{
				boxCollider.enabled = false;
			}
		}
	}

	public void AddBonuseToList(BonuseItem curBonuse)
	{
		if (!listAllBonuse.Contains(curBonuse))
		{
			listAllBonuse.Add(curBonuse);
			curBonuse.transform.parent = objSpisokAllBonuse.transform;
		}
	}

	private void GameModeChanged()
	{
		if (!settings.offlineMode)
		{
			listAllBonuse.ForEach(delegate(BonuseItem b)
			{
				UnityEngine.Object.Destroy(b.gameObject);
			});
			listAllBonuse.Clear();
		}
		if (settings.offlineMode || PhotonNetwork.isMasterClient)
		{
			SpawnBonuses();
		}
	}

	private void StartCreateBonuse()
	{
		if (settings.offlineMode || base.photonView.isMine)
		{
			iAmCreateBonuse = true;
			InvokeRepeating("CreateNewItemBonuse", timeAddItemBonuse, timeAddItemBonuse);
		}
	}

	private void StopCreateAllBonuse()
	{
		iAmCreateBonuse = false;
		CancelInvoke("CreateNewItemBonuse");
		CancelInvoke("CreateNewGunBonuse");
	}

	private void CreateNewItemBonuse()
	{
		CreateBonuseType(typeGroupBonuse.Item);
	}

	private void CreateNewGunBonuse()
	{
		CreateBonuseType(typeGroupBonuse.Guns);
	}

	public void CreateBonuseType(typeGroupBonuse needTypeBonuse)
	{
		CreateBonuseType(needTypeBonuse, true, Vector3.zero, -1, 0f);
	}

	public void DropBonuseTypeFromMob(typeGroupBonuse needTypeBonuse, bool isRandomPosition, Vector3 posRespawn, int radius, float offSetY, int chanceDropBonuseGroup, int minCount, int MaxCount, int chanceHeal, int chandeAmmo, int chanceJetpack)
	{
		int num = UnityEngine.Random.Range(0, 100);
		if (num < chanceDropBonuseGroup)
		{
			int num2 = UnityEngine.Random.Range(minCount, MaxCount + 1);
			for (int i = 0; i < num2; i++)
			{
				DropBonuse(needTypeBonuse, isRandomPosition, posRespawn, radius, offSetY, chanceHeal, chandeAmmo, chanceJetpack);
			}
		}
	}

	private void DropBonuse(typeGroupBonuse needTypeBonuse, bool isRandomPosition, Vector3 posRespawn, int radius, float offSetY, int chanceHeal, int chanceAmmo, int chanceJetpack)
	{
		int num = -1;
		num = chanceHeal + chanceAmmo + chanceJetpack;
		int num2 = UnityEngine.Random.Range(0, num);
		int num3 = 0;
		BonuseItem[] array = arrAllTypeBonuse;
		foreach (BonuseItem bonuseItem in array)
		{
			if (bonuseItem.typeGroup != needTypeBonuse)
			{
				continue;
			}
			switch (bonuseItem.id)
			{
			case idBonuse.Ammo:
				if (num2 < num3 + chanceAmmo)
				{
					addNewBonuse(bonuseItem, isRandomPosition, posRespawn, radius, offSetY, 100, 1, 1);
					return;
				}
				num3 += chanceAmmo;
				break;
			case idBonuse.Health:
				if (num2 < num3 + chanceHeal)
				{
					addNewBonuse(bonuseItem, isRandomPosition, posRespawn, radius, offSetY, 100, 1, 1);
					return;
				}
				num3 += chanceHeal;
				break;
			case idBonuse.Jetpack:
				if (num2 < num3 + chanceJetpack)
				{
					addNewBonuse(bonuseItem, isRandomPosition, posRespawn, radius, offSetY, 100, 1, 1);
					return;
				}
				num3 += chanceJetpack;
				break;
			}
		}
	}

	public void CreateBonuseType(typeGroupBonuse needTypeBonuse, bool isRandomPosition, Vector3 posRespawn, int radius, float offSetY, int verGenBonuse, int minCount, int MaxCount)
	{
		int num = UnityEngine.Random.Range(0, 100);
		if (num < verGenBonuse)
		{
			int num2 = UnityEngine.Random.Range(minCount, MaxCount + 1);
			for (int i = 0; i < num2; i++)
			{
				thisScript.CreateBonuseType(needTypeBonuse, isRandomPosition, posRespawn, radius, offSetY);
			}
		}
	}

	public void CreateBonuseType(typeGroupBonuse needTypeBonuse, bool isRandomPosition, Vector3 posRespawn, int radius, float offSetY, bool dropFromPlayer = true)
	{
		int max = -1;
		if (arrAllTypeBonuse != null)
		{
			BonuseItem[] array = arrAllTypeBonuse;
			foreach (BonuseItem bonuseItem in array)
			{
				if (bonuseItem.typeGroup == needTypeBonuse)
				{
					max = bonuseItem.totalVerGroup;
				}
			}
		}
		int num = UnityEngine.Random.Range(0, max);
		int num2 = 0;
		if (arrAllTypeBonuse != null)
		{
			BonuseItem[] array2 = arrAllTypeBonuse;
			foreach (BonuseItem bonuseItem2 in array2)
			{
				if (bonuseItem2.typeGroup == needTypeBonuse && (bonuseItem2.id != idBonuse.Jetpack || GameController.instance.curTypeGame != TypeGame.SkyBlock))
				{
					if (num < num2 + bonuseItem2.verAddThisBonuse)
					{
						addNewBonuse(bonuseItem2, isRandomPosition, posRespawn, radius, offSetY, 100, 1, 1, dropFromPlayer);
						return;
					}
					num2 += bonuseItem2.verAddThisBonuse;
				}
			}
		}
		BCWDebug.Log("error ver bonuse");
	}

	public void CreateBonuseWithId(idBonuse curIdBonuse, bool isRandomPosition, Vector3 posRespawn, int radius, float offSetY, int verGenBonuse, int minCount, int MaxCount)
	{
		if (settings.offlineMode)
		{
			addNewBonuseWithId((int)curIdBonuse, isRandomPosition, posRespawn, radius, offSetY, verGenBonuse, minCount, MaxCount);
		}
		else
		{
			addNewBonuseWithId((int)curIdBonuse, isRandomPosition, posRespawn, radius, offSetY, verGenBonuse, minCount, MaxCount);
		}
	}

	private int GetCountBonuseType(typeGroupBonuse needType)
	{
		int num = 0;
		foreach (BonuseItem item in listAllBonuse)
		{
			if (!item.IsKilled && item.typeGroup == needType)
			{
				num++;
			}
		}
		return num;
	}

	private int GetMaxCountBonuseType(typeGroupBonuse needType)
	{
		switch (needType)
		{
		case typeGroupBonuse.Item:
			return maxKolBonuseItem;
		case typeGroupBonuse.Guns:
			return maxKolBonuseGun;
		case typeGroupBonuse.Money:
			return 999999;
		default:
			return 0;
		}
	}

	public GameObject[] addNewBonuseWithId(int curIdBonuse, bool isRandomPosition, Vector3 posRespawnBonuse, int radius, float offSetY, int verGenBonuse, int minCount, int MaxCount, bool dropFromPlayer = true)
	{
		if (!settings.offlineMode && !base.photonView.isMine)
		{
			return null;
		}
		BonuseItem bonuseItem = null;
		BonuseItem[] array = arrAllTypeBonuse;
		foreach (BonuseItem bonuseItem2 in array)
		{
			if (bonuseItem2.id == (idBonuse)curIdBonuse)
			{
				bonuseItem = bonuseItem2;
				break;
			}
		}
		if (bonuseItem == null)
		{
			return null;
		}
		return addNewBonuse(bonuseItem, isRandomPosition, posRespawnBonuse, radius, offSetY, verGenBonuse, minCount, MaxCount, dropFromPlayer);
	}

	public GameObject[] addNewBonuse(BonuseItem addBonuse, bool isRandomPosition, Vector3 posRespawnBonuse, int radius, float offSetY, int verGenBonuse, int minCount, int MaxCount, bool dropFromPlayer = true)
	{
		if (!settings.offlineMode && !base.photonView.isMine && iAmCreateBonuse)
		{
			StopCreateAllBonuse();
			return null;
		}
		if (isRandomPosition && GetMaxCountBonuseType(addBonuse.typeGroup) <= GetCountBonuseType(addBonuse.typeGroup))
		{
			return null;
		}
		int num = UnityEngine.Random.Range(0, 100);
		if (num <= verGenBonuse)
		{
			int num2 = UnityEngine.Random.Range(minCount, MaxCount + 1);
			GameObject[] array = new GameObject[num2];
			for (int i = 0; i < num2; i++)
			{
				array[i] = InstantBonuse(addBonuse, isRandomPosition, posRespawnBonuse, radius, offSetY, dropFromPlayer);
				if (dropFromPlayer)
				{
					BonuseItem component = array[i].GetComponent<BonuseItem>();
					component.UseTimerToDestroy = true;
					component.TimeToDestroy = 15f;
				}
			}
			return array;
		}
		return null;
	}

	public GameObject InstantBonuse(idBonuse id, bool isRandomPosition, Vector3 posRespawnBonuse, int radius = 0, float offSetY = 0f, bool dropFromPlayer = true)
	{
		return InstantBonuse(GetBonusItemForID(id), isRandomPosition, posRespawnBonuse, radius, offSetY, dropFromPlayer);
	}

	public GameObject InstantBonuse(BonuseItem addBonuse, bool isRandomPosition, Vector3 posRespawnBonuse, int radius, float offSetY, bool dropFromPlayer, object[] info = null)
	{
		pointRespawn = null;
		bool flag = true;
		Vector3 vector;
		if (isRandomPosition)
		{
			for (int i = 0; i < countIterationRandom; i++)
			{
				if (addBonuse.typeGroup == typeGroupBonuse.Item)
				{
					pointRespawn = arrItemBonuseRespawn[UnityEngine.Random.Range(0, arrItemBonuseRespawn.Count)];
				}
				if (addBonuse.typeGroup == typeGroupBonuse.Guns)
				{
					pointRespawn = arrGunBonuseRespawn[UnityEngine.Random.Range(0, arrGunBonuseRespawn.Length)];
				}
				flag = true;
				foreach (BoxCollider item in predPointRespawn)
				{
					if (item == pointRespawn)
					{
						flag = false;
						break;
					}
				}
				if (flag)
				{
					break;
				}
			}
			if (predPointRespawn.Count > countRandomBonuse)
			{
				predPointRespawn.RemoveAt(0);
			}
			predPointRespawn.Add(pointRespawn);
			float num = pointRespawn.size.x * pointRespawn.transform.localScale.x;
			float num2 = pointRespawn.size.z * pointRespawn.transform.localScale.z;
			vector = new Vector3(pointRespawn.transform.position.x + UnityEngine.Random.Range((0f - num) * 0.5f, num * 0.5f), pointRespawn.transform.position.y, pointRespawn.transform.position.z + UnityEngine.Random.Range((0f - num2) * 0.5f, num2 * 0.5f));
		}
		else
		{
			vector = posRespawnBonuse;
		}
		float num3 = radius;
		if (radius > 0)
		{
			float num4 = UnityEngine.Random.Range(1f, num3);
			if (UnityEngine.Random.Range(0, 2) == 0)
			{
				num4 *= -1f;
			}
			float num5 = UnityEngine.Random.Range(1f, num3);
			if (UnityEngine.Random.Range(0, 2) == 0)
			{
				num5 *= -1f;
			}
			vector = new Vector3(vector.x + num4, vector.y + 2f, vector.z + num5);
			RaycastHit hitInfo;
			if (Physics.Raycast(posRespawnBonuse, (vector - posRespawnBonuse).normalized, out hitInfo, num3, layerForSpawn) && hitInfo.collider.tag != "enemy" && hitInfo.collider.tag != "collidePoint")
			{
				vector = hitInfo.point;
			}
			if (Physics.Raycast(vector, Vector3.down, out hitInfo, float.PositiveInfinity, layerForSpawn))
			{
				vector = hitInfo.point;
			}
		}
		vector.y += offSetY;
		if (isRandomPosition)
		{
			foreach (BonuseItem item2 in listAllBonuse)
			{
				if (Vector3.Distance(item2.transform.position, vector) < 1f)
				{
					return InstantBonuse(addBonuse, isRandomPosition, posRespawnBonuse, radius, offSetY, dropFromPlayer);
				}
			}
		}
		GameObject gameObject = (settings.offlineMode ? ((GameObject)UnityEngine.Object.Instantiate(addBonuse.gameObject, vector, Quaternion.identity)) : ((!dropFromPlayer) ? PhotonNetwork.InstantiateSceneObject("Bonuse/" + addBonuse.gameObject.name, vector, Quaternion.identity, 0, info) : PhotonNetwork.Instantiate("Bonuse/" + addBonuse.gameObject.name, vector, Quaternion.identity, 0, null)));
		if (gameObject == null)
		{
			BCWDebug.Log("error create bonuse");
			return null;
		}
		return gameObject;
	}

	public void InstantBonuse(List<SpawnBonuse> listBonuse, float respawnTime, Vector3 posRespawnBonuse)
	{
		int sumAllProbability = 0;
		listBonuse.ForEach(delegate(SpawnBonuse x)
		{
			sumAllProbability += x.percent;
		});
		int num = UnityEngine.Random.Range(0, sumAllProbability);
		int num2 = 0;
		foreach (SpawnBonuse item in listBonuse)
		{
			num2 += item.percent;
			if (num2 < num)
			{
				continue;
			}
			Dictionary<string, object> dictionary = new Dictionary<string, object>();
			object[] array = new object[1];
			int num3 = 0;
			foreach (SpawnBonuse item2 in listBonuse)
			{
				Dictionary<string, object> dictionary2 = new Dictionary<string, object>();
				dictionary2.Add("count", item2.count);
				dictionary2.Add("idProduct", item2.idProduct);
				dictionary2.Add("percent", item2.percent);
				dictionary2.Add("spawnType", item2.spawnType);
				dictionary.Add("k" + num3, dictionary2);
				num3++;
			}
			array[0] = dictionary;
			GameObject gameObject = InstantBonuse(GetBonusItemForID(item.spawnType), false, posRespawnBonuse, 0, 0f, false, array);
			BonuseItem component = gameObject.GetComponent<BonuseItem>();
			component.listSpawnBonus = listBonuse;
			component.changeBonuse = true;
			if (respawnTime > 0f)
			{
				component.respwnTime = respawnTime;
			}
			if (!item.idProduct.Equals(string.Empty))
			{
				component.idProduct = item.idProduct;
				component.ChangeTexture();
				if (item.count != 0)
				{
					component.countItemAddMin = item.count;
				}
			}
			BonuseItem bonuseItem = component.RandomBonuse();
			component.ChangeBonuse((int)bonuseItem.id, bonuseItem.idProduct, bonuseItem.countItemAddMin);
			break;
		}
	}

	public GameObject InstantLocalBonuse(idBonuse id, Vector3 position)
	{
		BonuseItem bonusItemForID = GetBonusItemForID(id);
		return (GameObject)UnityEngine.Object.Instantiate(bonusItemForID.gameObject, position, Quaternion.identity);
	}

	public bool getBonuse(GameObject objPlayer, bool inCar, BonuseItem bonus)
	{
		if (GameController.instance.playerScript.isDead)
		{
			return false;
		}
		BonuseItem bonuseItem = null;
		switch (bonus.id)
		{
		case idBonuse.Ammo:
			if (inCar)
			{
				CarBehavior componentInParent = objPlayer.GetComponentInParent<CarBehavior>();
				if (componentInParent != null && componentInParent.carWithWeapon && !componentInParent.isDead && (componentInParent.countBulletCar < componentInParent.startCountBulletCar || bonus.collectAnyway))
				{
					int startCountBulletCar = componentInParent.startCountBulletCar;
					componentInParent.countBulletCar = startCountBulletCar;
					AllUnitaryAchievements.instance.collectBullets_50.Increment();
					bonuseItem = bonus;
				}
			}
			else if (GameController.instance.curTypeGame == TypeGame.Zombe)
			{
				foreach (WeaponSlot value in PlayerBehavior.MyPlayer.weaponManager.slots.Values)
				{
					if (value.weapon != null && value.name != "gear" && value.weapon.AddBulletFromBonuse())
					{
						bonuseItem = bonus;
					}
				}
			}
			else if ((bool)GameController.instance.weaponManagerScripts.currentWeaponScript && GameController.instance.weaponManagerScripts.currentWeaponScript.AddBulletFromBonuse())
			{
				AllUnitaryAchievements.instance.collectBullets_50.Increment();
				bonuseItem = bonus;
			}
			break;
		case idBonuse.Health:
			if (!inCar && GameController.instance.playerScript != null && GameController.instance.playerScript.health < GameController.instance.playerScript.maxHealth)
			{
				int maxHealth = GameController.instance.playerScript.maxHealth;
				GameController.instance.playerScript.health = maxHealth;
				PlayerBehavior.MyPlayer.lerpScript.incrementHealth++;
				AllUnitaryAchievements.instance.collectMedKits_50.Increment();
				bonuseItem = bonus;
			}
			break;
		case idBonuse.Armor:
			if (!inCar)
			{
				bool flag2 = EquipmentManager.GetEquipedArmorId != string.Empty || EquipmentManager.GetEquipedHatId != string.Empty || EquipmentManager.GetEquipedBootsId != string.Empty;
				if (GameController.instance.playerScript != null && flag2 && GameController.instance.playerScript.armor < GameController.instance.playerScript.maxArmor)
				{
					GameController.instance.playerScript.armor = GameController.instance.playerScript.maxArmor;
					bonuseItem = bonus;
				}
			}
			break;
		case idBonuse.Money:
		{
			PlayerBehavior playerScript = GameController.instance.playerScript;
			bool flag = true;
			if (playerScript != null && playerScript.isDead)
			{
				flag = false;
			}
			if (flag)
			{
				int num6 = UnityEngine.Random.Range(bonus.countItemAddMin, bonus.countItemAddMax + 1);
				settings.CathedExeptions += (int)((float)num6 * playerScript.GetCashMultiplier());
				FlyingPointsController.instance.AddFlyingPoints(bonus.transform.position, PointsType.Cash, num6, true);
				AllUnitaryAchievements.instance.collectCash_100.Increment();
				bonuseItem = bonus;
			}
			break;
		}
		case idBonuse.Jetpack:
			if (!inCar && (GameController.instance.playerScript.tController.jetpack.fuel.GetValue() < 95f || bonus.collectAnyway))
			{
				JetpackBehavior.ActivateNewBalloon();
				bonuseItem = bonus;
			}
			break;
		case idBonuse.Experience:
		{
			PlayerBehavior playerScript = GameController.instance.playerScript;
			if (playerScript != null && !playerScript.isDead)
			{
				int num4 = UnityEngine.Random.Range(bonus.countItemAddMin, bonus.countItemAddMax + 1);
				bonuseItem = bonus;
			}
			break;
		}
		case idBonuse.MissionStar:
			bonuseItem = bonus;
			break;
		case idBonuse.Respect:
		{
			int num5 = UnityEngine.Random.Range(bonus.countItemAddMin, bonus.countItemAddMax);
			if (PlayerBehavior.MyPlayer != null)
			{
				num5 = (int)((float)num5 * PlayerBehavior.MyPlayer.GetRestectMultiplier());
			}
			SessionReputationManager.Instance.AddReputation(num5);
			bonuseItem = bonus;
			break;
		}
		case idBonuse.Star:
		{
			int num7 = UnityEngine.Random.Range(bonus.countItemAddMin, bonus.countItemAddMax);
			FlyingPointsController.instance.AddFlyingPoints(bonus.transform.position, PointsType.Stars, num7, true, AddCups(num7));
			bonuseItem = bonus;
			break;
		}
		case idBonuse.Item:
		{
			BaseWeapon currentWeaponScript = PlayerBehavior.MyPlayer.weaponManager.currentWeaponScript;
			if (currentWeaponScript != null && currentWeaponScript.name == "SnowThrower" && bonus.idProduct == "Snowball")
			{
				if (currentWeaponScript.ammo != currentWeaponScript.maxAmmo)
				{
					currentWeaponScript.ammo += bonus.countItemAddMin * 3;
					bonuseItem = bonus;
				}
				break;
			}
			ProductComsumable productComsumable = MarketController.Instance.GetProduct("Weapons", "Gear", bonus.idProduct) as ProductComsumable;
			if (productComsumable == null)
			{
				BCWDebug.LogError(bonus.idProduct + " not exists in market!");
			}
			else if (productComsumable.maxCount > productComsumable.Count)
			{
				MarketController.Instance.BuyProduct(bonus.idProduct, true, bonus.countItemAddMin);
				MarketController.Instance.WeaponEquipped("gear", bonus.idProduct);
				bonuseItem = bonus;
			}
			break;
		}
		case idBonuse.UpWeaponInZombie:
			TDMController.instance.GetBonuse();
			bonuseItem = bonus;
			break;
		case idBonuse.RobberInventory:
			if (TDMController.myTeam == PunTeams.Team.blue)
			{
				CopsAndRobbersController.instance.PickUpInventoryBonus();
				bonuseItem = bonus;
			}
			break;
		case idBonuse.Boost:
			if (PlayerBehavior.MyPlayer != null && PlayerBehavior.MyPlayer.currentCar != null && PlayerBehavior.MyPlayer.currentCar.currentBoostAmount < 100f)
			{
				float currentBoostAmount = PlayerBehavior.MyPlayer.currentCar.currentBoostAmount;
				float num = 25f;
				float num2 = num;
				if (currentBoostAmount + num > 100f)
				{
					float num3 = currentBoostAmount + num - 100f;
					num2 = num - num3;
				}
				PlayerBehavior.MyPlayer.currentCar.freeBoostAmount += num2;
				bonuseItem = bonus;
			}
			break;
		}
		if (bonuseItem != null)
		{
			bonuseItem.ShowGetBonusAnimation();
			bonuseItem.DisableBonuse();
			return true;
		}
		return false;
	}

	public IEnumerator AddCups(int val)
	{
		CupsManager.Cups += val;
		yield return null;
	}

	public void RemoveBonuseFromList(BonuseItem delBonuse)
	{
		if (delBonuse != null && listAllBonuse.Contains(delBonuse))
		{
			listAllBonuse.Remove(delBonuse);
		}
	}

	private void playSoundBonuse()
	{
		if (VolumeController.IsSoundEnable)
		{
			NGUITools.PlaySound(soundBonuse);
		}
	}

	public void GenerateBonusesForKillingPlayer(Vector3 pos, bool isPrivate)
	{
		if (GameController.instance.curTypeGame != TypeGame.tanks && GameController.instance.curTypeGame != TypeGame.Zombe && GameController.instance.curTypeGame != TypeGame.CopsAndRobbers && GameController.instance.curTypeGame != TypeGame.SkyBlock && GameController.instance.curTypeGame != TypeGame.WalkingRobots)
		{
			bool flag = string.IsNullOrEmpty(PhotonNetwork.room.customProperties["pass"].ToString());
			bool flag2 = GameController.instance.curTypeGame == TypeGame.normal;
			if (flag && !isPrivate)
			{
				CreateBonuseWithId(idBonuse.Money, false, pos, 3, 0.1f, (!flag2) ? 30 : 30, 10, 10);
			}
			if (isPrivate || GameController.instance.curTypeGame == TypeGame.normal || settings.offlineMode)
			{
			}
			CreateBonuseType(typeGroupBonuse.Item, false, pos, 3, 0.1f, 33, 1, 1);
		}
	}

	public BonuseItem GetBonusItemForID(idBonuse id)
	{
		BonuseItem[] array = arrAllTypeBonuse;
		foreach (BonuseItem bonuseItem in array)
		{
			if (bonuseItem.id.Equals(id))
			{
				return bonuseItem;
			}
		}
		return null;
	}

	public string SendInfoBonuse()
	{
		string empty = string.Empty;
		Dictionary<string, object> dictionary = new Dictionary<string, object>();
		int num = 0;
		foreach (BonuseItem item in listAllBonuse)
		{
			Dictionary<string, object> dictionary2 = new Dictionary<string, object>();
			if (item.changeBonuse)
			{
				num++;
				dictionary2.Add("I", item.photonView.viewID);
				dictionary2.Add("B", (int)item.id);
				dictionary2.Add("P", item.idProduct);
				dictionary2.Add("T", item.respwnTime);
				dictionary.Add("k" + num, dictionary2);
			}
		}
		return Json.Serialize(dictionary);
	}

	public void Send(PhotonPlayer player)
	{
		string text = SendInfoBonuse();
		base.photonView.RPC("ParseBonuse", player, text);
	}

	[PunRPC]
	public void ParseBonuse(string parse)
	{
		Dictionary<string, object> dictionary = Json.Deserialize(parse) as Dictionary<string, object>;
		for (int i = 1; i <= dictionary.Count; i++)
		{
			Dictionary<string, object> dictionary2 = (Dictionary<string, object>)dictionary["k" + i];
			object value;
			dictionary2.TryGetValue("I", out value);
			int viewID = Convert.ToInt32(value);
			PhotonView photonView = PhotonView.Find(viewID);
			BonuseItem component = photonView.GetComponent<BonuseItem>();
			if (component != null)
			{
				object value2;
				dictionary2.TryGetValue("B", out value2);
				component.id = (idBonuse)Convert.ToInt32(value2);
				object value3;
				dictionary2.TryGetValue("P", out value3);
				component.idProduct = value3.ToString();
				object value4;
				dictionary2.TryGetValue("T", out value4);
				component.respwnTime = Convert.ToInt32(value4);
				component.ChangeTexture();
				component.OnOreol();
			}
		}
	}

	public void ChangeTeam()
	{
		StartCoroutine(ChangeTeamAfterDelay());
	}

	private IEnumerator ChangeTeamAfterDelay()
	{
		if (PlayerBehavior.MyPlayer == null)
		{
			yield return null;
		}
		if (PlayerBehavior.MyPlayer.localTeam == PunTeams.Team.red && GameController.instance.curTypeGame == TypeGame.Zombe)
		{
			foreach (BonuseItem element in listAllBonuse)
			{
				element.gameObject.SetActive(false);
			}
			yield break;
		}
		if (PlayerBehavior.MyPlayer.localTeam != PunTeams.Team.blue || GameController.instance.curTypeGame != TypeGame.Zombe)
		{
			yield break;
		}
		foreach (BonuseItem element2 in listAllBonuse)
		{
			element2.gameObject.SetActive(true);
		}
	}
}
